﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace MutilLanguage_Search.Controller.GetKeyWords
{
    class GetKeyWordsSyn
    {
        public static ListBox lbxTopKeyWordsSyn;
        public static void Analysis()
        {
            Define.Variables.contentSyn = Regex.Replace(Define.Variables.contentSyn, @"\d", string.Empty);
            Regex myRegex = new Regex(@"[^\w']+");
            string[] sString = myRegex.Split(Define.Variables.contentSyn);
            foreach (string subString in sString)
            {
                if (!subString.Equals(""))
                {
                    Data.Modify.setKeyWordsSyn(subString);
                }
            }
            int i = 1;
            foreach (KeyValuePair<string, int> kv in Data.Init.sdKeyWordsSyn.OrderByDescending(key => key.Value))
            {
                if (i <= 5)
                {
                    Data.Init.sdTopKeyWordsSyn.Add(kv.Key, kv.Value);
                    i++;
                }
                lbxTopKeyWordsSyn.Items.Add(kv.Key + "\t\t" + kv.Value.ToString());
            }
            Define.Variables.st.Stop();
            Console.WriteLine(Define.Variables.st.Elapsed.ToString());
            MergeSynonyms();
            foreach (KeyValuePair<string, int> kv in Data.Init.sdMergeSynonyms)
            {
               GetTopLinks.GetTopLinksSynonyms.Init(kv.Key);
            }
        }
        public static void MergeSynonyms()
        {
            foreach (KeyValuePair<string, int> kv in Data.Init.sdSynonyms )
            {

                foreach (KeyValuePair<string, int> kv1 in Data.Init.sdTopKeyWordsSyn)
                {
                    if (!kv.Key.Equals(kv1.Key))
                    {
                        Data.Init.sdMergeSynonyms.Add(kv.Key + "_" + kv1.Key,1);
                    }
                }
            }
        }
    }
}
